package com.dxy.hms.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.dxy.hms.base.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dxy.hms.model.entity.Config;
import com.dxy.hms.service.ConfigService;

/**
* <p>
* 配置表 controller
* </p>
*
* @author dxy
* @since 2024-10-07
*/
@Slf4j
@Api(tags = "配置表接口")
@RestController
@RequestMapping("/hms/config")
public class ConfigController {

    @Autowired
    private ConfigService service;

    @ApiOperation("增加")
    @PostMapping("/add")
    public Resp add(@RequestBody Config entity) {
        service.add(entity);
        return Resp.bizSuccess();
    }

    @ApiOperation("根据id修改")
    @PostMapping("/updById")
    public Resp updById(@RequestBody Config entity) {
        service.updById(entity);
        return Resp.bizSuccess();
    }

    @ApiOperation("根据id删除")
    @PostMapping("/delByIds")
    public Resp delByIds(@RequestBody List<Long> ids) {
        service.delByIds(ids);
        return Resp.bizSuccess();
    }

    @ApiOperation("详情")
    @GetMapping("/getDetail")
    public Resp<Config> getDetail(Long id) {
        return Resp.bizSuccess(service.getDetail(id));
    }

    @ApiOperation("分页")
    @GetMapping("/getPage")
    public Resp<IPage<Config>> getPage(Long pageNum, Long pageSize) {
        return Resp.bizSuccess(service.getPage(pageNum, pageSize));
    }

    @ApiOperation("根据key获取")
    @GetMapping("/getByKey/{key}")
    public Resp getByKey(@PathVariable("key")String key){
        return Resp.bizSuccess(service.getOne(new LambdaQueryWrapper<Config>().eq(Config::getConfKey,key)));
    }


}